package cc.catface.common;

import java.math.BigDecimal;

public class StringT {

    public static String convertDouble2String(double d) {
        BigDecimal bd = new BigDecimal(String.valueOf(d));
        return bd.stripTrailingZeros().toPlainString();
    }

    public static String convertDouble2String2(double d) {
        if (Math.round(d) - d == 0) {
            return String.valueOf((long) d);
        }
        return String.valueOf(d);
    }

    public static void main(String[] args) {
        System.out.println(convertDouble2String(5.1));
        System.out.println(convertDouble2String(5.0));
        System.out.println(convertDouble2String(5));

        System.out.println(convertDouble2String2(5.1));
        System.out.println(convertDouble2String2(5.0));
        System.out.println(convertDouble2String2(5));
    }
}
